package com.dkf.springcloud.listen;

import com.dkf.springcloud.bean.User;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;

import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@RabbitListener(queues = "Queue3")
public class Consumer {

    @RabbitHandler
    public void listen(User user, Message message, Channel channel) throws IOException {
        // 采用手动应答模式, 手动确认应答更为安全稳定
         channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
        System.out.println("Listener received: " + user);
    }

}
